package com.amtf.datafile2.core.txt;

import com.amtf.datafile2.DataField;
import com.amtf.datafile2.core.std.StdDataFieldFormatPad;

public class TxtDataFieldFormatPadLeft extends StdDataFieldFormatPad {

	public TxtDataFieldFormatPadLeft(int length, String padValue) {
		super(length, padValue);
	}

	// public static final DataFieldPadType<String> instance = new TxtDataFieldPadLeft();

	public String format(DataField value) {
		return format(value.getValue());
	}

	public String format(Object value) {
		return format(value.toString());
	}

	public String format(String value) {
		if (padValue.length() != 0 && length > 0 && value != null && value.length() > 0) {
			String padString = "";
			int spaceCount = length - value.length();
			for (int i = 0; i < spaceCount; i++) {
				padString += padValue;
			}

			return padString + value;
		}

		return value;
	}
}
